import ACCESS_ENUM from "@/access/accessEnum";

const checkAccess = (user: any, needAccess = ACCESS_ENUM.GUEST) => {
  const userAccess = user?.userRole ?? ACCESS_ENUM.GUEST;

  if (needAccess === ACCESS_ENUM.GUEST) {
    return true;
  }
  if (needAccess === ACCESS_ENUM.USER) {
    if (userAccess !== ACCESS_ENUM.GUEST) {
      return true;
    }
  }
  if (needAccess === ACCESS_ENUM.ADMIN) {
    if (userAccess !== ACCESS_ENUM.ADMIN) {
      return false;
    }
  }
  return true;
};

export default checkAccess;
